package com.imooc.mall.controller;

import com.github.pagehelper.PageInfo;
import com.imooc.mall.common.ApiRestResponse;
import com.imooc.mall.service.OrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 订单后台管理controller
 */
@RestController

public class OrderAdminController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/admin/order/list")
    public ApiRestResponse listForAdmin(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize){
        PageInfo pageInfo = orderService.listForAdmin(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    /**
     * 后台订单发货功能
     */
    @PostMapping("/admin/order/delivered")
    @ApiOperation("后台发货功能")
    public ApiRestResponse delivered(@RequestParam String orderNo){
        orderService.delivered(orderNo);
        return ApiRestResponse.success();
    }
    /**
     * 订单完结功能
     */
    @PostMapping("/order/finish")
    @ApiOperation("订单完结功能（管理员和普通用户都可以调用）")
    public ApiRestResponse finish(String orderNo){
        orderService.finish(orderNo);
        return ApiRestResponse.success();


    }

    

}
